/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
/**
 * This example demonstrates how to read settings from a settings-file.
 */

#include "gimi.h"

int main(int argc, char **argv) {
  int sleeptime = 10;
  std::string configfile = "tutorialsettings.xml";

  // Initialize dPrint.
  debugInit();
  debugSetGlobalDebugLvl(6);
  
  // Create the GIMI-object.
  dPrint(1, "Create object.");
  gimi::GIMI gi;

  // Read settings.
  if (gi.readSettings(configfile)) {
    dPrint(1, "Configuration succesfully read from %s", configfile.c_str());
  } else {
    dPrint(1, "Failed to read configuration from %s", configfile.c_str());
    return -1;
  }
    
  // Connect to tcphub with settings read from configuration file.
  if (!gi.connectToHub()) {
    dPrint(1, "Could not connect to tcpHub. Are connection parameters correct?");
    return -1;
  }
  
  // Read parameter for sleep if given.
  if (argc > 1) {
    if (argv[1] != NULL)
      sleeptime = atoi(argv[1]);
  }
  
  // Sleep for a while so results of reading settings can be checked with
  // serviceDiscovery by another client.
  sleep(sleeptime);
  
  
  // GIMI-destructor handles disconnecting

  // Closes logfile in case if it was used. (dPrint)
  debugDeinit();
  
  return 0;
}
